<?php

namespace App\Services\UtilManage;

class ResponseService
{
    public $code_success = 0;
    public $code_fail = 1;

    public $http_status_200 = 200;
    public $http_status_500 = 500;
    public $http_status_401 = 401;
    public $digit = 5;


    function success($body){
        $result =  response()->json(['code'=>$this->code_success,'body'=>$body], $this->http_status_200);
        $result = $this->encrypt($result);
        return $result;
    }
    function fail($body){
        $result =  response()->json(['code'=>$this->code_fail,'body'=>$body], $this->http_status_200);
        $result = $this->encrypt($result);
        return $result;
    }
    

    function encrypt($result){
        if(env('APP_DEV_ENV' ) == 'production'){

            $str = substr(md5(time()),0 ,$this->digit) . base64_encode(json_encode($result));
            $arr['code'] = $str;
            return $arr;
        }else{
            return $result;
        }
    }


}